import { ref } from 'vue'
import { getTodoId } from '../util/todoStorage.js'

export function useNewTodo(todoListRef) {
  let newDoRef = ref('')
  const addListRef = () => {
    const value = newDoRef.value && newDoRef.value.trim()
    if (!value) return
    let task = {
      id: getTodoId(),
      content: newDoRef.value,
      isFinish: false
    }
    todoListRef.value.push(task)
    newDoRef.value = ''
  }
  return {
    newDoRef,
    addListRef
  }
}